package com.airy.highSpeed.controller;

import com.airy.highSpeed.entity.TrHourFlowEntity;
import com.airy.highSpeed.service.TrHourFlowService;
import com.airy.highSpeed.utils.PageUtils;
import com.airy.highSpeed.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Author: Ding Ya Kun.
 * @Description:
 * @Date:Created in 2020.12.22 9:09
 */
@RestController
@RequestMapping("product/trhourflow")
public class TrHourFlowController {
    @Autowired
    private TrHourFlowService trHourFlowService;

    /**
     * 查询所有
     */
    @RequestMapping("/findAll")
    public R findAll(){
        List<TrHourFlowEntity> cpcEntityList = trHourFlowService.findAll();

        return R.ok().put("长度",cpcEntityList.size());
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = trHourFlowService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
        TrHourFlowEntity trHourFlowEntity = trHourFlowService.getById(id);

        return R.ok().put("trHourFlowEntity", trHourFlowEntity);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TrHourFlowEntity trHourFlowEntity){
        trHourFlowService.save(trHourFlowEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TrHourFlowEntity trHourFlowEntity){
        trHourFlowService.updateById(trHourFlowEntity);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
        trHourFlowService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
    /**
     * 插入
     */
    @RequestMapping("/insertTrHourFlow")
    public void insertTrHourFlow(TrHourFlowEntity trHourFlowEntity) {
        trHourFlowService.insertTrHourFlow(trHourFlowEntity);
    }

    public void updateEtcFlowAndMtcFlowBySTARTTIMEAndSTATIONID(String startTime, String tollStationId, Integer flage, Integer etcFlow, Integer mtcFlow,String insertTime) {
        trHourFlowService.updateEtcFlowAndMtcFlowBySTARTTIMEAndSTATIONID(startTime,tollStationId,flage,etcFlow,mtcFlow,insertTime);
    }
}
